import {get,post,del} from "../tools/request"

//获取用户购物车数据
export const lodaCart = () => get('/api/v1/shop_carts')

//增减购物车数量
export const lodaNumChange = (id, num) => post("/api/v1/shop_carts", {
    product:id,
    amount:num
})

//随机取几件商品
export const randomPrd=(num=4)=>{
    let i,arr=[];
    return new Promise(function(resolvd,reject){
        get("/api/v1/products",{}).then(r=>{
            i=r.total
            get("/api/v1/products",{per:i}).then(r=>{
                for(let l=0;arr.length<num;l++){
                    arr.push(r.data.splice(Math.round(Math.random() * r.data.length), 1))
                }
                resolvd(arr.flat())
            })
        })
    })
}
//删除购物车商品
export  const removePrd=(id)=>{
    return del('/api/v1/shop_carts/'+id)
}
